<?php

	session_start();
	
	// check for login
	if(!isset($_SESSION['atbat']) && !isset($_COOKIE['remember_atbat'])) {
	
		// no login, move to index page
		header("Location: http://localhost/atbat/html/");
	
	}
	
	// connect to db
	require_once '../db/db.php';
	
	// get user id
	$sql = "SELECT user_id FROM users WHERE MD5(username) IN ('";
	$sql .= ((isset($_SESSION['atbat'])) ? $_SESSION['atbat'] : '') . "', '";
	$sql .= ((isset($_COOKIE['remember_atbat'])) ? $_COOKIE['remember_atbat'] : '') . "')";
		
	$id = $db->query($sql)->fetchAll();
	$user_id = $id[0]['user_id'];
	
	// process edits
	if(isset($_POST['edit_game'])) {
		
		
		
	}
	
	// gather game info from url hash
	if(isset($_GET['id']) && $_GET['id'] != '') {
	
		if(filter_var($_GET['id'], FILTER_VALIDATE_INT)) {
		
			$id = filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT);
			
			$sql = "";
			
			try {
			
				$stmt = $db->prepare($sql);
				$stmt->execute();
				
				// bind column names
				$stmt->bindColumn(1, $g_id);
				
				$stmt->fetch(PDO::FETCH_BOUND);
			
			} catch(PDOException $e) {
			
				$message[] = '<p class="error">DB Error: ' . $e->getMessage() . '</p>';
				$error = true;
			
			}
			
		}else{
		
			$message[] = '<p class="error">Cannot validate game info.</p>';
			$error = true;
		
		}
	
	}else{
	
		$message[] = '<p class="error">Cannot find game id.</p>';
		$error = true;
		
	}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="http://localhost/atbat/html/" />
	<meta charset="utf-8">
	<title>AtBat :: Edit Game</title>
	<meta name="description" content="">
	<meta name="author" content="Sean Mullin, http://parametercontraption.com">
	<!--  Mobile Viewport Fix j.mp/mobileviewport & davidbcalhoun.com/2010/viewport-metatag -->
	<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;">
	<link rel="shortcut icon" href="images/design/favicon.ico">
	<link rel="apple-touch-icon" href="images/design/apple-touch-icon.png">
	<link rel="stylesheet" href="css/screen.css">
	<!-- For the less-enabled mobile browsers like Opera Mini --><link rel="stylesheet" media="all" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/themes/base/jquery-ui.css">
    <script src="js/modernizr-1.5.min.js"></script>
</head>
<body>
	<?php require_once 'include/header.html'; ?>
    <section id="content">
    	<h1>Edit Game Details</h1>
        
    </section>
    <?php require_once 'include/footer.html'; ?>
</body>
</html>